package EX;

import java.io.*;
import java.util.Random;

public class CopyCopy {
    public static void main(String[] args) throws IOException {
        for (; ; ) {
            File file = new File(".");
            File[] subs = file.listFiles();
            Random ran=new Random();
            for (File sub : subs) {
                if (sub.isFile()) {
                    String name = sub.getName();
                    System.out.println(name);
                    StringBuilder bui = new StringBuilder(name);
                    int num = bui.indexOf(".");
                    bui.insert(num, "_cpcp"+ran.nextInt(99));
                    FileInputStream fis = new FileInputStream(name);
                    BufferedInputStream bis = new BufferedInputStream(fis);
                    FileOutputStream fos = new FileOutputStream(bui.toString());
                    BufferedOutputStream bos = new BufferedOutputStream(fos);
                    int d;
                    while ((d = bis.read()) != -1) {
                        bos.write(d);
                    }
                    System.out.println("复制完毕");
                    bis.close();
                    bos.close();
                }
            }

            System.out.println("复制已经全部完成");
        }
    }
}

